<template>
    <view class="mainimg">
        <view class="swiper_square">
            <view class="counter" v-if="state.materialList.length">
                {{ currentImgNum }}/{{ state.materialList.length }}
            </view>
            <swiper circular="true" autoplay="true" class="swiper_content" interval="5000" @change="changeSwiper">
                <swiper-item v-for="(item, index) in state.materialList" :key="index">
                    <image
                        class="tabimg"
                        :src="item?.materialSrc || defaultImg"
                        :lazy-load="true"
                        mode="aspectFill"></image>
                </swiper-item>
            </swiper>
        </view>
    </view>
</template>
<script setup>
import { getImgOssUrl } from '@/commons/utils';
import { computed, ref } from 'vue';

const props = defineProps({
    data: { type: Object, default: () => ({}) }
});
const defaultImg = getImgOssUrl('/ui-prod-2.0.0/errorImg.png');
const currentImgNum = ref(1);
const changeSwiper = e => {
    currentImgNum.value = e.detail.current + 1;
};
const state = computed(() => {
    const data = Object.assign({}, props.data);
    (data?.materialList || []).sort((a, b) => {
        return a.sort - b.sort;
    });
    return data;
});
// currentImgNum.value = state.value.currentCoverIndex + 1;
</script>
<style lang="scss" scoped>
.mainimg {
    background-color: #ffff;
    .swiper_square {
        position: relative;
        .counter {
            position: absolute;
            bottom: 22rpx;
            right: 28rpx;
            z-index: 1;
            padding: 8rpx 24rpx;
            background: rgba(51, 51, 51, 0.5);
            border-radius: 26rpx;
            font-size: 26rpx;
            font-weight: 400;
            color: #ffffff;
            line-height: 36rpx;
        }
        .swiper_content {
            height: 750rpx;
            .tabimg {
                height: 100%;
                width: 100%;
            }
        }
    }
}
</style>
